package core

import (
	"bytes"
	"encoding/binary"
)

func IntToBytes(n int) []byte {
	x := int32(n)
	bf := bytes.NewBuffer([]byte{})
	binary.Write(bf, binary.LittleEndian, x)
	return bf.Bytes()
}

func IntToBytesBE(n int) []byte {
	x := int32(n)
	bf := bytes.NewBuffer([]byte{})
	binary.Write(bf, binary.BigEndian, x)
	return bf.Bytes()
}

func BytesToInt(b []byte) int {
	bf := bytes.NewBuffer(b)
	var x int32
	binary.Read(bf, binary.LittleEndian, &x)
	return int(x)
}

func BytesToIntBE(b []byte) int {
	bf := bytes.NewBuffer(b)
	var x int32
	binary.Read(bf, binary.BigEndian, &x)
	return int(x)
}
